<?php

include_once 'Database.php';

class Ticket extends Database {
	private $id;
	private $titel;
	private $description;
	private $comments;
	private $solution;
	private $sla;
	private $create_time;
	private $creator;
	private $editor;
	private $priority;
	private $status;
	private $category;
	
	function __construct($id, $titel, $description, $comments, $solution, $sla, $create_time, $creator, $priority, $status, $category) {
		parent::__construct();
		$this->id = intval($id);
		$this->titel = $titel;
		$this->description = $description;
		$this->comments = $comments;
		$this->solution = $solution;
		$this->sla = $sla;
		$this->create_time = $create_time;
		$this->creator = $creator;
		$this->editor = null;
		$this->priority = $priority;
		$this->status = $status;
		$this->category = $category;
	}
	
	public function getId() {
		return $this->id;
	}
	
	public function getTitel() {
		return $this->titel;
	}
	
	public function getDescription() {
		return $this->description;
	}
	
	public function getComments() {
		return $this->comments;
	}
	
	public function getSolution() {
		return $this->solution;
	}
	
	public function getSla() {
		return $this->sla;
	}
	
	public function getCreate_time() {
		return $this->create_time;
	}
	
	public function getCreator() {
		return $this->creator;
	}
	
	public function getEditor() {
		return $this->editor;
	}
	
	public function getPriority() {
		return $this->priority;
	}
	
	public function getStatus() {
		return $this->status;
	}
	
	public function getCategory() {
		return $this->category;
	}
	
	public function deleteTicket() {
		try {
			$querry = "DELETE FROM `ticket` WHERE `id` = ?";
			$stmt = $this->db->prepare($querry);
			if($stmt) {
				$stmt->bind_param('i', $this->id);
				if($stmt->execute()) {
					return true;
				}
				print_r($stmt);
			}
		} catch(Exception $e) {
			return false;
		}
		return false;
	}
	
	public function getTicketHtmlTable() {
		$row = '<tr onclick="document.location=' . "'###'" . ';"><td>' . $this->titel . '</td><td>' . $this->category . '</td><td>' . $this->priority . '</td><td>' . $this->status . '</td>';
		return $row;
	}
}